import java.util.Arrays;

/**
 * Created with IntelliJ IDEA
 * Description 练习数组
 * User: 王杰
 * Date: 2025-05-16
 * Time: 13:46
 */
public class Test {

    // 多数元素
    public static int func4(int[] array) {
        Arrays.sort(array);
        return array[array.length / 2];
    }

    public static void main(String[] args) {
        int[] array = {3,2,3};
        int ret = func4(array);
        System.out.println(ret);
    }
    public static int func3(int[] array) {
        int ret = 0;
        for (int i = 0; i < array.length; i++) {
            ret ^= array[i];
        }
        return ret;
    }
    public static void main2(String[] args) {
        int[] array = {2,2,7,7,5,6,6};
        int ret = func3(array);
        System.out.println(ret);
    }
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9};
        func1(array);
        System.out.println(Arrays.toString(array));
    }

    public static void func1(int[] array) {
        int left = 0;
        int right = array.length - 1;
        while (left < right) {
            while (left < right && array[left] % 2 != 0) {
                left++;
            }
            while (left < right && array[right] % 2 == 0) {
                right--;
            }
            swap(array, left, right);
        }
    }

    private static void swap(int[] array, int i, int j) {
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }

}
